<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="js/jquery-3.4.1.js"></script>
	</head>
	<body>
		<form>
			用户名：<input type="text" id="userName" />
			学号：<input type="text" id="stuNo" />
			密码：<input type="password" id="password" />
			重复密码：<input type="password" id="password2" />
			<input type="submit" id="userLogin" value="登录" />
			<input type="button" id="submit" value="提交" />
		</form>
		<script>
			$("#userLogin").click(function () {
				window.location.href="userLogin.html";
			});
			$("#submit").click(function(){
				userName=$("#userName").val();
				upassword=$("#password").val();
				upassword2=$("#password2").val();
				stuNo=$("#stuNo").val();
				if(userName=="" || upassword=="" || upassword2=="" || stuNo==""){
					alert("信息未填全");
				}else if(upassword!=upassword2){
					alert("两次密码不一致");
				}else{
					$.ajax({
						"url":"/studentDemo/NewUserServlet",
						"data":{'stuNo':stuNo,'userName':userName,'password':upassword},
						"success":function(responseData){
							var data=JSON.parse(responseData);
							switch(data.result){
								case "ok":
									alert(data.msg);
									window.location.href="userLogin.html";
									break;
								case "error":
									alert(data.msg);
									break;
								default:
									alert("出错啦");
									break;
							}
						},
						"error":function(){
							alert("发送失败");
						}
					})
				}
			});
		</script>
	</body>
	
</html>
